<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="附件ID" prop="attachmentId">
        <el-input v-model="queryParams.attachmentId" placeholder="请输入附件ID" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="文件名" prop="fileName">
        <el-input v-model="queryParams.fileName" placeholder="请输入文件名" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="文件虚拟路径" prop="filePath">
        <el-input v-model="queryParams.filePath" placeholder="请输入文件虚拟路径" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="文件大小" prop="fileSize">
        <el-input v-model="queryParams.fileSize" placeholder="请输入文件大小" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="上传时间" prop="uploadDate">
        <el-date-picker clearable v-model="queryParams.uploadDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择上传时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="attributeCategory">
        <el-input v-model="queryParams.attributeCategory" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute1">
        <el-input v-model="queryParams.attribute1" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute2">
        <el-input v-model="queryParams.attribute2" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute3">
        <el-input v-model="queryParams.attribute3" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute4">
        <el-input v-model="queryParams.attribute4" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute5">
        <el-input v-model="queryParams.attribute5" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute6">
        <el-input v-model="queryParams.attribute6" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute7">
        <el-input v-model="queryParams.attribute7" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute8">
        <el-input v-model="queryParams.attribute8" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute9">
        <el-input v-model="queryParams.attribute9" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute10">
        <el-input v-model="queryParams.attribute10" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute11">
        <el-input v-model="queryParams.attribute11" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute12">
        <el-input v-model="queryParams.attribute12" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute13">
        <el-input v-model="queryParams.attribute13" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute14">
        <el-input v-model="queryParams.attribute14" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="${comment}" prop="attribute15">
        <el-input v-model="queryParams.attribute15" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini"
                   @click="handleAdd" v-hasPermi="['basic:sysFile:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                   @click="handleUpdate" v-hasPermi="['basic:sysFile:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                   @click="handleDelete" v-hasPermi="['basic:sysFile:remove']">删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExport" v-hasPermi="['basic:sysFile:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sysFileList" @selection-change="handleSelectionChange" border height="calc(100vh - 300px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="fileId" />
      <el-table-column label="附件ID" align="center" prop="attachmentId" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="文件名" align="center" prop="fileName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="文件虚拟路径" align="center" prop="filePath" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="文件大小" align="center" prop="fileSize" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="文件类型" align="center" prop="fileType" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="上传时间" align="center" prop="uploadDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.uploadDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="attributeCategory" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute1" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute2" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute3" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute4" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute5" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute6" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute7" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute8" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute9" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute10" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute11" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute12" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute13" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute14" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="${comment}" align="center" prop="attribute15" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['basic:sysFile:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete"
                     @click="handleDelete(scope.row)" v-hasPermi="['basic:sysFile:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <!-- 添加或修改关联附件对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="附件ID" prop="attachmentId">
          <el-input v-model="form.attachmentId" placeholder="请输入附件ID" />
        </el-form-item>
        <el-form-item label="文件名" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名" />
        </el-form-item>
        <el-form-item label="文件虚拟路径" prop="filePath">
          <el-input v-model="form.filePath" placeholder="请输入文件虚拟路径" />
        </el-form-item>
        <el-form-item label="文件大小" prop="fileSize">
          <el-input v-model="form.fileSize" placeholder="请输入文件大小" />
        </el-form-item>
        <el-form-item label="上传时间" prop="uploadDate">
          <el-date-picker clearable v-model="form.uploadDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择上传时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="attributeCategory">
          <el-input v-model="form.attributeCategory" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute1">
          <el-input v-model="form.attribute1" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute2">
          <el-input v-model="form.attribute2" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute3">
          <el-input v-model="form.attribute3" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute4">
          <el-input v-model="form.attribute4" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute5">
          <el-input v-model="form.attribute5" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute6">
          <el-input v-model="form.attribute6" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute7">
          <el-input v-model="form.attribute7" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute8">
          <el-input v-model="form.attribute8" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute9">
          <el-input v-model="form.attribute9" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute10">
          <el-input v-model="form.attribute10" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute11">
          <el-input v-model="form.attribute11" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute12">
          <el-input v-model="form.attribute12" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute13">
          <el-input v-model="form.attribute13" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute14">
          <el-input v-model="form.attribute14" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="attribute15">
          <el-input v-model="form.attribute15" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSysFile, getSysFile, delSysFile, addSysFile, updateSysFile } from "@/api/basic/sysFile";

export default {
  name: "SysFile",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 关联附件表格数据
      sysFileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        attachmentId: null,
        fileName: null,
        filePath: null,
        fileSize: null,
        fileType: null,
        uploadDate: null,
        attributeCategory: null,
        attribute1: null,
        attribute2: null,
        attribute3: null,
        attribute4: null,
        attribute5: null,
        attribute6: null,
        attribute7: null,
        attribute8: null,
        attribute9: null,
        attribute10: null,
        attribute11: null,
        attribute12: null,
        attribute13: null,
        attribute14: null,
        attribute15: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询关联附件列表 */
    getList() {
      this.loading = true;
      listSysFile(this.queryParams).then(response => {
        this.sysFileList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fileId: null,
        attachmentId: null,
        fileName: null,
        filePath: null,
        fileSize: null,
        fileType: null,
        uploadDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        attributeCategory: null,
        attribute1: null,
        attribute2: null,
        attribute3: null,
        attribute4: null,
        attribute5: null,
        attribute6: null,
        attribute7: null,
        attribute8: null,
        attribute9: null,
        attribute10: null,
        attribute11: null,
        attribute12: null,
        attribute13: null,
        attribute14: null,
        attribute15: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fileId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加关联附件";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fileId = row.fileId || this.ids
      getSysFile(fileId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改关联附件";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fileId != null) {
            updateSysFile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSysFile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fileIds = row.fileId || this.ids;
      this.$modal.confirm('是否确认删除关联附件编号为"' + fileIds + '"的数据项？').then(function() {
        return delSysFile(fileIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basic/sysFile/export', {
        ...this.queryParams
      }, `sysFile_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
